﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：PersonCardInfo
// 文件功能描述：卡证管理
//
// 
// 创建标识：2012-02-15 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    public class PersonCardInfo
    {
        /// <summary>
        /// 人员ID
        /// </summary>
        public int PID
        {
            get;
            set;
        }
        /// <summary>
        /// 人员编号
        /// </summary>
        public string EmpNo
        {
            get;
            set;
        }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string deptName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员类型
        /// </summary>
        public string PersonTypeName
        {
            get;
            set;
        }
        /// <summary>
        /// 人员姓名
        /// </summary>
        public string PName
        {
            get;
            set;
        }
        /// <summary>
        /// 部门编号
        /// </summary>
        public int Dep_ID
        {
            get;
            set;
        }
        /// <summary>
        /// 卡序列号
        /// </summary>
        public Int64 CardSerial
        {
            get;
            set;
        }
        /// <summary>
        /// 押金
        /// </summary>
        public int CardOptDeposit
        {
            get;
            set;
        }
        /// <summary>
        /// 开户金额
        /// </summary>
        public int Balance
        {
            get;
            set;
        }
        /// <summary>
        /// 有效期始
        /// </summary>
        public DateTime InureTime
        {
            get;
            set;
        }
        /// <summary>
        /// 有效期止
        /// </summary>
        public DateTime ExpiredTime
        {
            get;
            set;
        }
        /// <summary>
        /// 操作员
        /// </summary>
        public string OperatorID
        {
            get;
            set;
        }
        public bool blSubsidyCard
        {
            get;
            set;
        }
        /// <summary>
        /// 月补贴金额
        /// </summary>
        public decimal BTMoney
        {
            get;
            set;
        }
        /// <summary>
        /// 月补贴上限
        /// </summary>
        public decimal BTSX
        {
            get;
            set;
        }

        private DataAccessPersonCard dar;
        private int PersonCardcount;
        public int _PersonCardcount
        {
            get { return PersonCardcount; }
        }
        public PersonCardInfo(bool isgetcount)
        {
            dar = new DataAccessPersonCard();
            if (isgetcount)
            {
                PersonCardcount = GetPersonCardCount();
            }
        }
        public PersonCardInfo()
        { }

        /// <summary>
        /// 获取未发卡人员数量
        /// </summary>
        /// <returns></returns>
        private int GetPersonCardCount()
        {
            return dar.GetPersonCardCount();
        }

        /// <summary>
        /// 根据条件获取未发卡人员数量
        /// </summary>
        /// <returns></returns>
        public int GetPersonCardCountWhere(string query)
        {
            return dar.GetPersonCardCountWhere(query);
        }

        /// <summary>
        /// 获取未发卡人员信息（分页）
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public IList<PersonCardInfo> SelPersonCardInfo(int pagesize, int startindex, string strquery)
        {
            IList<PersonCardInfo> perlist = new List<PersonCardInfo>();
            PersonCardInfo perinfo;
            DataSet ds = dar.SelPersonCardInfo(pagesize, startindex, strquery);
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                perinfo = new PersonCardInfo()
                {
                    PID = Convert.ToInt32(item["PID"]),
                    EmpNo = item["EmpNo"].ToString(),
                    deptName = item["deptName"].ToString(),
                    PersonTypeName = "员工卡",
                    PName = item["PName"].ToString()
                };
                perlist.Add(perinfo);
            }
            return perlist;
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            return dar.GetdeptName();
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetDept()
        {
            return dar.GetDept();
        }

        /// <summary>
        /// 根据编号获取一条人员信息
        /// </summary>
        /// <param name="supplierNo"></param>
        /// <returns></returns>
        public PersonCardInfo GetPersonCardInfoOne(string id)
        {
            dar = new DataAccessPersonCard();
            DataSet ds = dar.GetPersonCardInfoOne(id);
            PersonCardInfo info = new PersonCardInfo();
            info.PID = int.Parse(ds.Tables[0].Rows[0]["PID"].ToString());
            info.EmpNo = ds.Tables[0].Rows[0]["EmpNo"].ToString();
            info.deptName = ds.Tables[0].Rows[0]["deptName"].ToString();
            info.PersonTypeName = "员工卡";
            info.PName = ds.Tables[0].Rows[0]["PName"].ToString();
            info.Dep_ID = int.Parse(ds.Tables[0].Rows[0]["Dep_ID"].ToString());
            return info;
        }

        public int SaveGrantCard(PersonCardInfo per)
        {
            object[] objper = new object[] { per.EmpNo, per.CardSerial, per.CardOptDeposit, per.InureTime, per.ExpiredTime, per.Balance, per.OperatorID, per.blSubsidyCard };
            return dar.SaveGrantCard(objper);
        }

        public int SaveGrantCardTemp(PersonCardInfo per)
        {
            object[] objper = new object[] { per.EmpNo, per.CardSerial, per.CardOptDeposit, per.InureTime, per.ExpiredTime, per.Balance, per.OperatorID, per.PName, per.Dep_ID, per.blSubsidyCard, per.BTMoney, per.BTSX };
            return dar.SaveGrantCardTemp(objper);
        }

        public bool CheckCardSerial(Int64 CardSerial)
        {
            int count = dar.CheckCardSerial(CardSerial);
            return count > 0 ? false : true;
        }

        public bool CheckEmpNo(int EmpNo)
        {
            int count = dar.CheckEmpNo(EmpNo);
            return count > 0 ? false : true;
        }
    }
}
